local INVENTORY_GRID = {}

function INVENTORY_GRID:Init()
	self.Icon = "devin/blackbetty/hudicons/inventoryslot.png"
	self.NumCol = 10
	self.NumRows = 6
	self.CellSize = 48
	self.HoveredCell = 0
	self.OldHoveredCell = 1
	self.CellInfo = {}
	self.CellInfo[1] = {}
	self.CellInfo[1].HoldingItem = false
	self.CellInfo[1].ItemNumber = 0
	self.CellInfo[1].ItemHeight = 1
	self.CellInfo[1].ItemWidth = 1
	self.CellInfo[1].X_Offset = 0
	self.CellInfo[1].Y_Offset = 0
	self.CellInfo[1].Color = Color(255, 255, 255, 255)
	self.CellToDraw = 1
	self:CreateCells()
end

function INVENTORY_GRID:CreateCells()
	local CellNum = 1
	for i = 1, self.NumRows, 1 do
		for k = 1, self.NumCol, 1 do
			self.CellInfo[CellNum] = {}
			self.CellInfo[CellNum].HoldingItem = false
			self.CellInfo[CellNum].ItemNumber = 0
			self.CellInfo[CellNum].ItemHeight = 1
			self.CellInfo[CellNum].ItemWidth = 1
			self.CellInfo[CellNum].X_Offset = ((k * self.CellSize)-self.CellSize)
			self.CellInfo[CellNum].Y_Offset = ((i * self.CellSize)-self.CellSize)
			self.CellInfo[CellNum].Color = Color(255, 255, 255, 255)
			self.CellInfo[CellNum].Icon = "devin/blackbetty/hudicons/inventoryslot.png"
			CellNum = CellNum + 1
		end
	end
end

function INVENTORY_GRID:Paint()
	local x, y = self:GetPos()
	local width, height = self:GetSize()
	--surface.SetMaterial(Material( self.CellInfo[i].Icon ) )
	surface.SetDrawColor(Color(0, 0, 0, 255))
	surface.DrawTexturedRect(30, ScrH() - 30, 50, 200)
	
		
	--for i = 1, #self.CellInfo, 1 do
		--surface.SetMaterial(Material( self.CellInfo[i].Icon ) )
		--surface.SetDrawColor(self.CellInfo[i].Color)
		--surface.DrawTexturedRect(self.CellInfo[i].X_Offset, self.CellInfo[i].Y_Offset, self.CellSize, self.CellSize)
	--end
end

function INVENTORY_GRID:Think()
	local xpos, ypos = self:LocalCursorPos()
	local xmult_ = math.Round((xpos/self.CellSize)+0.5, 0)		
	local ymult_ = math.Round((ypos/self.CellSize)+0.5, 0)
	local xmult = math.Clamp(xmult_, 0, self.NumCol)
	local ymult = math.Clamp(ymult_, 0, self.NumRows)
	if((xpos >= 0 and ypos >= 0) and ((xpos <= self.CellSize * self.NumCol) and (ypos <= self.CellSize * self.NumRows)))then
		self.HoveredCell = math.Round((xmult + ((ymult*self.NumCol)-self.NumCol)), 0)
		self.CellInfo[self.HoveredCell].Color = Color(200, 255, 200, 255)
	end
	
	if(self.HoveredCell != self.OldHoveredCell and self.HoveredCell > 0 or !(((xpos <= self.CellSize * self.NumCol) and (ypos <= self.CellSize * self.NumRows))))then
		self.CellInfo[self.OldHoveredCell].Color = Color(255, 255, 255, 255)
		if(self.HoveredCell > 0)then
			self.OldHoveredCell = self.HoveredCell
		end
	end
end

vgui.Register( "TalentWindow", INVENTORY_GRID, "DImage")